package com.ruoyi.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.manage.domain.EventSurgery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.SurgeryPlan;
import com.ruoyi.manage.service.ISurgeryPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 手术计划Controller
 *
 * @author liuyangyang
 * @date 2025-05-28
 */
@Api("手术计划")
@RestController
@RequestMapping("/manage/surgeryplan")
public class SurgeryPlanController extends BaseController {
    @Autowired
    private ISurgeryPlanService surgeryPlanService;

    /**
     * 查询手术计划列表
     */
    @ApiOperation("查询手术计划列表")
    @PreAuthorize("@ss.hasPermi('manage:surgeryplan:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurgeryPlan surgeryPlan) {
        startPage();
        List<SurgeryPlan> list = surgeryPlanService.selectSurgeryPlanList(surgeryPlan);
        return getDataTable(list);
    }

    /**
     * 导出手术计划列表
     */
    @PreAuthorize("@ss.hasPermi('manage:surgeryplan:export')")
    @Log(title = "手术计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurgeryPlan surgeryPlan) {
        List<SurgeryPlan> list = surgeryPlanService.selectSurgeryPlanList(surgeryPlan);
        ExcelUtil<SurgeryPlan> util = new ExcelUtil<SurgeryPlan>(SurgeryPlan.class);
        util.exportExcel(response, list, "手术计划数据");
    }

    /**
     * 获取手术计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:surgeryplan:query')")
    @GetMapping(value = "/{surgeryId}")
    public AjaxResult getInfo(@PathVariable("surgeryId") Long surgeryId) {
        return success(surgeryPlanService.selectSurgeryPlanBySurgeryId(surgeryId));
    }

    /**
     * 新增手术计划
     */
    @ApiOperation("新增手术计划")
    @PreAuthorize("@ss.hasPermi('manage:surgeryplan:add')")
    @Log(title = "手术计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurgeryPlan surgeryPlan) {
        return toAjax(surgeryPlanService.insertSurgeryPlan(surgeryPlan));
    }

    /**
     * 修改手术计划
     */
    @ApiOperation("修改手术计划")
    @PreAuthorize("@ss.hasPermi('manage:surgeryplan:edit')")
    @Log(title = "手术计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurgeryPlan surgeryPlan) {
        return toAjax(surgeryPlanService.updateSurgeryPlan(surgeryPlan));
    }

    /**
     * 删除手术计划
     */
    @ApiOperation("删除手术计划")
    @PreAuthorize("@ss.hasPermi('manage:surgeryplan:remove')")
    @Log(title = "手术计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{surgeryIds}")
    public AjaxResult remove(@PathVariable Long[] surgeryIds) {
        return toAjax(surgeryPlanService.deleteSurgeryPlanBySurgeryIds(surgeryIds));
    }

    /**
     * 开始手术计划
     */
    @ApiOperation("开始手术计划")
    @Log(title = "开始手术")
    @GetMapping(value = "/start")
    public AjaxResult startSurgery(@RequestParam("surgeryId") Long surgeryId) {
        return success(surgeryPlanService.startSurgery(surgeryId));
    }

    /**
     * 取消
     */
    @ApiOperation("取消手术计划")
    @Log(title = "取消手术")
    @PostMapping(value = "/cancel")
    public AjaxResult cancelSurgery(@RequestParam("surgeryId") Long surgeryId, @RequestParam("status") String status) {
        return success(surgeryPlanService.cancelSurgery(surgeryId, status));
    }

    @ApiOperation("出室")
    @Log(title = "出室")
    @PostMapping(value = "/out")
    public AjaxResult outSurgery(@RequestBody EventSurgery eventSurgery) {
        return success(surgeryPlanService.outSurgery(eventSurgery));
    }

    @ApiOperation("恢复至待入室")
    @Log(title = "恢复至待入室")
    @PostMapping(value = "/reset")
    public AjaxResult resetSurgery(@RequestParam("surgeryId") Long surgeryId, @RequestParam("status") String status) {
        return success(surgeryPlanService.resetSurgery(surgeryId, status));
    }

}
